
--攻击带电----------------------------------------------------------------
local function fn_electricattacks(attacker, data)
    if data.weapon ~= nil then
        if data.projectile == nil then
            --in combat, this is when we're just launching a projectile, so don't do FX yet
            if data.weapon.components.projectile ~= nil then
                return
            elseif data.weapon.components.complexprojectile ~= nil then
                return
            elseif data.weapon.components.weapon:CanRangedAttack() then
                return
            end
        end
        if data.weapon.components.weapon ~= nil and data.weapon.components.weapon.stimuli == "electric" then
            --weapon already has electric stimuli, so probably does its own FX
            return
        end
    end
    if data.target ~= nil and data.target:IsValid() and attacker:IsValid() then
        SpawnPrefab("electrichitsparks"):AlignToTarget(data.target,
            data.projectile ~= nil and data.projectile:IsValid() and data.projectile or attacker, true)
    end
end
---启用攻击带电
---@param enable boolean
---@param player ent
---@param weapon ent
local function enable_electricattacks(enable, player, weapon)
    if enable then
        if player.components.electricattacks == nil then
            player:AddComponent("electricattacks")
        end
        player.components.electricattacks:AddSource(weapon)
        player:ListenForEvent("onattackother", fn_electricattacks)
        SpawnPrefab("electricchargedfx"):SetTarget(player)
    else
        if player.components.electricattacks ~= nil then
            player.components.electricattacks:RemoveSource(weapon)
        end
        player:RemoveEventCallback("onattackother", fn_electricattacks)
    end
end


 enable_electricattacks(true, owner, inst)--打开带电
 enable_electricattacks(false, owner, inst)--关闭带电